#include<iostream>	
#include<string>
#include<algorithm>
using namespace std;
string s;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		cin >> s;
	/*	if (s == " LR") {
			cout << 1 << endl;
			continue;
		}*/
		int l = 0, r = 0;
		int f1 = 0, f2 = 0;
		for (int i = 0; i < n; i++) {
			if (s[i] == 'L') {
				f1++;
			}
			else {
				f2++;
			}
		}	
		if (f1 == s.size() || f2 == s.size()) {
			cout << -1 << endl;
			continue;
		}
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == 'R') {
				r = i;
				break;
			}
		}
		for (int i = s.size() - 1; i >= 0; i--) {
			if (s[i] == 'L') {
				l = i;
				break;
			}
		}
		if (l > r) {
			cout << 0 << endl;
		}
		else if (l + 1 == r) {
			cout << l + 1 << endl;
		}
		else {
			cout << -1 << endl;
		}
		////cout <<"l and r "<< l << " " << r << endl;
		int ans = l - 1 + n - r;
		//cout <<ans << endl;
	}
	return 0;
}
